"""CSV field name details.
"""
import unittest

import chardata

chardata.initData()

source = ["code",
          "name",
          "category",
          "combining",
          "bidi",
          "decomposition",
          "decimal",
          "digit",
          "numeric",
          "mirrored",
          "unicode10",
          "comment",
          "upper",
          "lower",
          "title",]

destination = ["code",
               "name",
               "block",
               "category_code",
               "category",
               "html_entity",
               "combining",
               "bidi_code",
               "bidi",
               "decomposition",
               "decimal",
               "digit",
               "numeric",
               "mirrored",
               "unicode10",
               "comment",
               "upper",
               "lower",
               "title",]

def removeAngleBracketQuotes(value):
  if value.startswith("<") and value.endswith(">"):
    return value[1:-1]
  return value

def safeTitleCase(value):
  value = value.title()
  value = value.replace("Cjk", "CJK")
  return value

mapping = [("code", lambda d: int(d["code"], 16)),
           ("name", lambda d: removeAngleBracketQuotes(d["name"])),
           ("name", lambda d: safeTitleCase(d["name"])),
           ("category_code", lambda d: d["category"]),
           ("category", lambda d: chardata.getGeneralCategory(d["category_code"])),
           ("block", lambda d: chardata.getBlockName(d["code"])),
           ("bidi_code", lambda d: d["bidi"]),
           ("bidi", lambda d: chardata.getBidiCategory(d["bidi_code"])),
           ("unicode10", lambda d: d["unicode10"].title()),
           ("html_entity", lambda d: chardata.getEntityName(d["code"])),]

class FieldNamesTestCase(unittest.TestCase):
  def test(self):
    for item in mapping:
      name = item[0]
      self.assertTrue(name in destination)
  
  def testRemoveAngleBracketQuotes(self):
    testvalue = "<CJK Ideograph Extension A, First>"
    expected = "CJK Ideograph Extension A, First"
    actual = removeAngleBracketQuotes(testvalue)
    self.assertEqual(expected, actual)
